package com.huihe.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huihe.common.entity.AjaxResult;
import com.huihe.framework.service.SysMenuService;
import com.huihe.framework.vo.SysMenuVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 菜单 Controller 层
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/menu")
public class SysMenuController {

    /**
     * 角色 Service 层
     */
    SysMenuService sysMenuService;

    /**
     * 根据 ID 查询
     * @return 角色
     */
    @GetMapping(path = "/{id}")
    public AjaxResult findById(@PathVariable(name = "id") String id){
        SysMenuVo result = sysMenuService.findById(id);
        return AjaxResult.success(result);
    }

    /**
     * 条件查询-不分页
     * @return 查询结果
     */
    @PostMapping(path = "/searchAll")
    public AjaxResult findByList(@RequestBody Map<String, Object> dto){
        List<SysMenuVo> result = sysMenuService.findByList(dto);
        return AjaxResult.success(result);
    }

    /**
     * 条件查询-分页
     * @return 查询结果
     */
    @PostMapping(path = "/search")
    public AjaxResult findByPage(@RequestBody Map<String, Object> dto){
        IPage<SysMenuVo> result = sysMenuService.findByPage(dto);
        return AjaxResult.success(result);
    }

    /**
     * 条件查询-树
     * @return 查询结果
     */
    @PostMapping(path = "/findTree")
    public AjaxResult findTree(@RequestBody Map<String, Object> dto){
        List<SysMenuVo> result = sysMenuService.findTree(dto);
        return AjaxResult.success(result);
    }

    /**
     * 创建
     * @return 创建结果
     */
    @PostMapping
    public AjaxResult create(@RequestBody SysMenuVo vo){
        boolean result = sysMenuService.create(vo);
        return AjaxResult.success();
    }

    /**
     * 更新
     * @return 更新结果
     */
    @PutMapping
    public AjaxResult update(@RequestBody SysMenuVo vo){
        boolean result = sysMenuService.update(vo);
        return AjaxResult.success();
    }

    /**
     * 根据ID删除
     * @return 删除结果
     */
    @DeleteMapping(path = "/{id}")
    public AjaxResult deleteById(@PathVariable(name = "id") String id){
        boolean result = sysMenuService.deleteById(id);
        return AjaxResult.success();
    }
}
